/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bbd.crawler.dao.fwk;

import bbd.crawler.dao.ibatis.SQLMapFactory;
import bbd.crawler.vo.fwk.BaseVO;

import com.ibatis.sqlmap.client.SqlMapClient;
import java.util.List;

/**
 *
 * @author Amogh
 */
public class BaseDAO {

    private SqlMapClient sqlClient = null;

    //--------------------------------------------------------------------------
    /** Javadoc here */
    public BaseDAO () throws Exception {

        sqlClient = SQLMapFactory.getClientInstance ();

    } // end default constructor

    //--------------------------------------------------------------------------
    /** Javadoc here */
    protected List get ( BaseVO bvo, String query ) throws Exception {

        // get a list of objects
        return sqlClient.queryForList (query, bvo);

    } // end function insert

    //--------------------------------------------------------------------------
    /** Javadoc here */
    protected boolean insert ( BaseVO bvo, String query ) throws Exception {

        // insert is successful if a null is returned
        return ( sqlClient.insert (query, bvo) == null );

    } // end function insert

    //--------------------------------------------------------------------------
    /** Javadoc here */
    protected boolean update ( BaseVO bvo, String query ) throws Exception {

        // update is successful if 1 or more records are updated
        return ( sqlClient.update (query, bvo) >= 1 );

    } // end function update

    //--------------------------------------------------------------------------
    /** Javadoc here */
    protected boolean delete ( BaseVO bvo, String query ) throws Exception {

        // delete is successful if 1 or more records are deleted
        return ( sqlClient.delete (query, bvo) >= 1 );

    } // end function delete

    //--------------------------------------------------------------------------
    /** Javadoc here */
    protected List get ( String query ) throws Exception {

        // get a list of objects
        return sqlClient.queryForList (query);

    } // end function insert

    //--------------------------------------------------------------------------
    /** Javadoc here */
    protected boolean insert ( String query ) throws Exception {

        // insert is successful if a null is returned
        return ( sqlClient.insert (query) == null );

    } // end function insert

    //--------------------------------------------------------------------------
    /** Javadoc here */
    protected boolean update ( String query ) throws Exception {

        // update is successful if 1 or more records are updated
        return ( sqlClient.update (query) >= 1 );

    } // end function update

    //--------------------------------------------------------------------------
    /** Javadoc here */
    protected boolean delete ( String query ) throws Exception {

        // delete is successful if 1 or more records are deleted
        return ( sqlClient.delete (query) >= 1 );

    } // end function delete

} // end class BaseDAO
